import { DisposeView } from "../../../mvc/core/DisposeView";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { PageTool } from "../../../common/global/PageTool";
import { AttachedSoulBattlefieldOperateVo } from "./vo/AttachedSoulBattlefieldOperateVo";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { ResFileConst } from "../../resource/ResFileConst";
import { Cache } from "../../cache/Cache";
import { GameConst } from "../../../component/gconst/GameConst";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { Language } from "../../../../extend/language/Language";
import { AIManager } from "../../scene/ai/AIManager";
import { MsgManager } from "../../manager/MsgManager";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SecTimerView } from "../common/SecTimerView";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GBitmap } from "../../../../com/mui/controls/GBitmap";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { AttachedSoulBattlefielApplyRenderer } from "./renderer/AttachedSoulBattlefielApplyRenderer";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class AttachedSoulBattlefielApplyPanel
    
    export  class AttachedSoulBattlefielApplyPanel extends DisposeView
    {
        constructor()
        {
            super();
            this._radioBtnArr = new Vector.<GRadioButton>();
            this._pageTool = new PageTool([], 12);
            return;
        }

        /* internal  */onClickJoinBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var vo: AttachedSoulBattlefieldOperateVo;
            var onBtnClickHandler: Function;
            var onBtnClickMulHandler: Function;
            var isNeedAlert: Boolean;

            var loc1;
            vo = null;
            onBtnClickHandler = null;
            isNeedAlert = false;
            e = arg1;
            onBtnClickHandler = (arg1: int, arg2: Boolean): void
            {
                if (arg1 == Alert.YES) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AttachedSoulBattlefieldJoin, vo));
                }
                if (arg2) 
                {
                    PulseSharedObject.save("AttachedSoulBattlefielJoin", true);
                }
                return;
            }
            onBtnClickMulHandler = (arg1: int, arg2: Boolean): void
            {
                if (arg1 == Alert.YES) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AttachedSoulBattlefieldJoin, vo));
                }
                if (arg2) 
                {
                    PulseSharedObject.save("AttachedSoulBattlefielJoinMul", true);
                }
                return;
            }
            vo = new AttachedSoulBattlefieldOperateVo();
            vo.incomeType = 0;
            if (this._joinBtn.styleName != ResFileConst.GangFightsJoin) 
            {
                vo.signUpFlag = 0;
                Dispatcher.dispatchEvent(new DataEvent(EventName.AttachedSoulBattlefieldJoin, vo));
            }
            else 
            {
                vo.signUpFlag = 1;
                isNeedAlert = !PulseSharedObject.isTodayNotTips("AttachedSoulBattlefielJoin");
                if (isNeedAlert && Cache.instance.attachedSoulBattlefield.todaySpiritCoin > GameConst.SpiritCoinDailyMax) 
                {
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(Language.getString(28611), null, Alert.YES | Alert.NO, null, onBtnClickHandler);
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.AttachedSoulBattlefieldJoin, vo));
            }
            return;
        }

        /* internal  */getMulMoney(arg1: int): int
        {
            if (arg1 == 2) 
            {
                return 10;
            }
            if (arg1 == 3) 
            {
                return 30;
            }
            return 0;
        }

        /* internal  */onExchangeLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._npcTarget) 
            {
                hide();
                AIManager.onAutoPathAIControl(this._npcTarget);
            }
            return;
        }

        /* internal  */onClickReturnBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._pageSelecter.updatePageTxt(int(this._inputTxt.text));
            return;
        }

        /* internal  */onClickLinkTxtHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SpiritEquipWindowOpen));
            return;
        }

        /* internal  */onPosTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=false;
            var loc3=null;
            var loc4=0;
            var loc2=Cache.instance.role.playerInfo.playerId;
            var loc5=0;
            var loc6=this._pageTool.array;
            for(loc3 of loc6) 
            {
                if (loc3.playerId != loc2) 
                {
                    continue;
                }
                loc1 = true;
                loc4 = Math.ceil((this._pageTool.array.indexOf(loc3) + 1) / this._pageTool.limit);
                this._pageSelecter.updatePageTxt(loc4);
                break;
            }
            if (!loc1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(28633));
            }
            return;
        }

        /* internal  */onListPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=this._pageSelecter.currentPage;
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(loc1));
            this._list.drawNow();
            return;
        }

        /* internal  */onInputTxtChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (int(this._inputTxt.text) > this._pageSelecter.maxPage) 
            {
                this._inputTxt.text = this._pageSelecter.maxPage.toString();
            }
            return;
        }

        public set applyList(arg1: Array<any>)
        {
            this._pageTool.array = arg1;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._list.drawNow();
            return;
        }

        public joinOrCancelSuccess(): void
        {
            var loc1=Cache.instance.attachedSoulBattlefield;
            if (loc1.joinOrCancelSuccess) 
            {
                this._joinBtn.styleName = ResFileConst.GangFightsCancel;
            }
            else 
            {
                this._joinBtn.styleName = ResFileConst.GangFightsJoin;
            }
            if (loc1.joinCoolTime > 0) 
            {
                this.addChild(this._coolTime);
                this._coolTime.setLeftTime(loc1.joinCoolTime);
            }
            else 
            {
                DisplayUtil.removeMe(this._coolTime);
                this._coolTime.stop();
            }
            return;
        }

        public set todaySpiritCoin(arg1: int)
        {
            this._todaySpiritCoin.text = Language.getStringByParam(28612, arg1, GameConst.SpiritCoinDailyMax);
            this._totalSoulNum.htmlText = Language.getStringByParam(28616, Cache.instance.role.money.spiritCoin);
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._bgLong.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossBg);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 190, 478, this));
            pushUIToDisposeVec(ObjCreate.createBg(193, 0, 601, 440, this));
            this._name = ObjCreate.createGTextField(Language.getStringByParam(28571, HTMLUtil.addColor(Cache.instance.role.playerInfo.name, GlobalStyle.color2)), 10, 28, 180, 20, this, null, true);
            this._totalSoulNum = ObjCreate.createGTextField("", 10, 55, 180, 20, this);
            this._integral = ObjCreate.createGTextField("", 10, 82, 180, 20, this);
            this._coolTime = new SecTimerView();
            this._coolTime.mouseEnabled = false;
            this._coolTime.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 18, GlobalStyle.color7Uint, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._coolTime.filters = [FilterConst.glowFilter];
            ObjCreate.setObjAttri(this._coolTime, 39, 150, 110, 38);
            this._bgLong = new GBitmap();
            ObjCreate.setObjAttri(this._bgLong, 1, 220, -1, -1, this);
            LoaderHelp.addResCallBack(ResFileConst.areanCrossMain, this.onResCompl);
            this._joinBtn = ObjCreate.createGLoadedButton(ResFileConst.GangFightsJoin, 43, 200, 102, 88, this);
            this._joinBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onClickJoinBtnHandler);
            this._todaySpiritCoin = ObjCreate.createGTextField("", 10, 82, 180, 20, this);
            this._npcTarget = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENPCEffectSpiritCoinChange, 800503);
            var loc1=ObjCreate.createGTextField(Language.getString(28617), 130, 54, 28, 20, this, GlobalStyle.textFormatWhite, true);
            loc1.configEventListener(flash.events.TextEvent.LINK, this.onExchangeLinkHandler);
            pushUIToDisposeVec(loc1);
            this._pageSelecter = ObjCreate.createPageSelecter(350, 452, this);
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.configEventListener(flash.events.Event.CHANGE, this.onListPageChange);
            this._list = ObjCreate.createTileList(210, 30, 600, 415, this);
            this._list.scrollPolicy = ScrollPolicy.OFF;
            this._list.columnWidth = 600;
            this._list.rowHeight = 34;
            this._list.setStyle("cellRenderer", AttachedSoulBattlefielApplyRenderer);
            this._inputTxt = ObjCreate.createGTextInput(512, 453, 69, 20, this);
            this._inputTxt.restrict = "0-9";
            this._inputTxt.configEventListener(flash.events.Event.CHANGE, this.onInputTxtChangeHandler);
            var loc2=ObjCreate.createGButton(Language.getString(28591), 620, 450, 62, 24, this);
            loc2.configEventListener(flash.events.MouseEvent.CLICK, this.onClickReturnBtnHandler);
            pushUIToDisposeVec(loc2);
            var loc3=ObjCreate.createGTextField(Language.getString(28592), 720, 452, 55, 20, this, GlobalStyle.textFormatWhite, true);
            loc3.mouseEnabled = true;
            loc3.configEventListener(flash.events.TextEvent.LINK, this.onPosTxtLinkHandler);
            pushUIToDisposeVec(loc3);
            var loc4;
            (loc4 = ObjCreate.createGTextField("", 18, 365, 160, 100, this, GlobalStyle.setTextFormatLeading(GlobalStyle._textFormat1, 5))).wordWrap = true;
            loc4.multiline = true;
            loc4.htmlText = Language.getString(28583);
            loc4.configEventListener(flash.events.TextEvent.LINK, this.onClickLinkTxtHandler);
            pushUIToDisposeVec(loc4);
            var loc5;
            (loc5 = ObjCreate.createGTextField(Language.getString(28604), 485, 452, 150, 40, this, GlobalStyle._textFormat2)).mouseEnabled = false;
            pushUIToDisposeVec(loc5);
            var loc6=GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat2, flash.text.TextFormatAlign.CENTER);
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 190, 25, this, ImagesConst.TileBg));
            pushUIToDisposeVec(ObjCreate.createBg(192, -3, 606, 25, this, ImagesConst.RbListHeader));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28575), 40, 125, 120, 20, this, GlobalStyle._textFormat6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28572), 10, 4, 150, 20, this, GlobalStyle._textFormat6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28585), 210, 4, 80, 20, this, loc6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28586), 290, 4, 160, 20, this, loc6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28587), 450, 4, 130, 20, this, loc6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28588), 580, 4, 130, 20, this, loc6));
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28589), 710, 4, 80, 20, this, loc6));
            pushUIToDisposeVec(ObjCreate.createBg(10, 108, 170, 2, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(ObjCreate.createBg(10, 345, 170, 2, this, ImagesConst.SplitLine));
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            this._bgLong.dispose(arg1);
            this._name.dispose(arg1);
            this._totalSoulNum.dispose(arg1);
            this._coolTime.dispose(arg1);
            this._joinBtn.dispose(arg1);
            this._integral.dispose(arg1);
            this._pageSelecter.dispose(arg1);
            this._radioBtnArr = new Vector.<GRadioButton>();
            this._bgLong = null;
            this._name = null;
            this._totalSoulNum = null;
            this._coolTime = null;
            this._joinBtn = null;
            this._integral = null;
            this._pageSelecter = null;
            return;
        }

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_totalSoulNum: GTextFiled;

        /* internal */ /* var */_coolTime: SecTimerView;

        /* internal */ /* var */_bgLong: GBitmap;

        /* internal */ /* var */_joinBtn: GLoadedButton;

        /* internal */ /* var */_integral: GTextFiled;

        /* internal */ /* var */_todaySpiritCoin: GTextFiled;

        /* internal */ /* var */_radioBtnArr: Vector.<GRadioButton>;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_inputTxt: GTextInput;

        /* internal */ /* var */_npcTarget: TaskTargetInfo;
    }
